<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org/">
<head th:replace="page/index::head">

</head>
<body class="layui-layout-body layuimini-all">
<div class="layui-layout layui-layout-admin">

    <div class="layui-header header" th:replace="page/index::nav">
    </div>

    <div class="layui-side layui-bg-black" th:replace="page/index::left">
    </div>

    <div class="layui-body">
        <div class="layuimini-content-page">
            <!--初始化中间内容-->
            <div class="layuimini-container layui-anim layui-anim-upbit ">
                <div class="layuimini-main content">
                    <form class="layui-form" action="" method="post">
                        <div class="layui-form-item">
                            <label class="layui-form-label">公告标题</label>
                            <div class="layui-input-block">
                                <input type="text" name="noticeTitle" required lay-reqtext="标题不能为空"
                                       lay-verify="required" placeholder="请输入标题"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">公告内容</label>
                            <div class="layui-input-block">
                                <textarea name="noticeContent" placeholder="请输入内容" lay-reqtext="内容不能为空"
                                          class="layui-textarea"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" lay-submit lay-filter="issue">立即发布</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>
                    <p class="errorMag" style="width: 318.4px;
                    height: 30px;padding-top: 40px;padding-left:350px;
                    text-align: center;color: crimson" th:text="${errorMsg}"></p>

                </div>
            </div>
        </div>
    </div>

</div>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" src="../../static/lib/jquery-3.4.1/jquery-3.4.1.min.js"
        charset="utf-8"></script>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" src="../../static/lib/layui-v2.5.5/layui.js?v=1.0.4"
        charset="utf-8"></script>
<script th:src="@{/lib/layui-v2.5.5/layui.all.js}" src="../../static/lib/layui-v2.5.5/layui.js?v=1.0.4"
        charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" src="../../static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script type="text/javascript">

    layui.use(['layer', 'layuimini'], function () {
        $('.login-out').on("click", function () {
            layer.msg('正在退出登录', function () {
                window.location = '/user/logout';
            });
        });
        /* layuimini.listen();*/
    });
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;

        form.on('submit(issue)',function (data) {
            data = data.field;
            $.post("/notice/issue",
                {noticeTitle:data.noticeTitle,noticeContent:data.noticeContent},
                function (result) {
                if (result.code==1){
                    //出现错误
                    layer.msg(result.msg);
                }else{
                    layer.prompt({
                        type: 1,
                        content: result.msg+'，点击确定前往公告列表',
                        area: ['500px','300px'],
                        title: '提示信息',
                        btnAlign: 'c',
                        yes: function (index, layero) {
                            //点击确定查看发布过的公告
                           window.location.href="/notice/list";
                        }
                    });
                }
            });
        });
    });
    /*头像上传*/
    $(".uploadAvatar").click(function () {
        layer.open({
            type: 1
            , title: '上传头像' //不显示标题栏
            , closeBtn: 2
            , area: '300px;'
            , id: 'upload-avatar' //设定一个id，防止重复弹出
            , resize: false
            , btnAlign: 'c'
            , moveType: 1 //拖拽模式，0或者1
            , content: $(".magt3")

        });
        layui.use('upload', function () {
            var upload = layui.upload;
            var uploadInst = upload.render({
                elem: '#test1'
                ,auto:true

                , url: '/user/projectPictureUpload'
                , method: 'post'
                , accept: 'images'
                , acceptMime: 'image/*'
                , field: 'projectImg'
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        $("#demo1").attr('src',result);
                    })}
                , done: function (res) {
                    //如果上传失败
                    if (res.status == 1) {
                        return layer.msg('上传项目图片失败', {icon: 5});
                    }
                    //上传成功,获得图片地址
                    console.log(res.data);

                    $('.avatar').attr('src', res.data);
                    layer.closeAll();
                    // window.location.reload();
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });
    });
</script>
</body>

<!--上传头像框-->
<div class="layui-form layui-form-item magt3">

    <div class="layui-upload">
        <button type="button" class="layui-btn" style="margin-left: 100px;" id="test1">选择图片</button>
        <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1" style="margin-left:80px;width: 140px;height: 115px;">
            <p id="demoText"></p>
        </div>

    </div>

</div>
</html>